#! /usr/bin/python
# -*- coding:utf-8 -*-
from queue import Queue

#db index, desc, type, len, stx
DB_DATA = [
    #PDI
    [1304,"plate_id","string",19,2],
    [1304,"material_id","string",19,24],
    [1304,"steel grade","string",19,78],
    [1304,"plate length","float",4,44],
    [1304,"plate width","float",4,48],
    [1304,"plate thickness","float",4,52],
    [1304,"yield point","float",4,56],
    [1304,"tensile strength","float",4,60],

    [1304,"RULER_1M_CROSS","float",4,64],
    [1304,"RULER_1M_LENGTH","float",4,68],
    [1304,"RULER_2M_LENGTH","float",4,72],
    # [1304,"plate cassette no","word",2,194],
    
    [1304,"plate act temperature","float",4,196],

    # [1205,"Cassette_change_car set transport1 speed" ,"float",4,662],
    # [1205,"Cassette_change_car set transport2 speed","float",4,666],
    # [1205,"Cassette_change_car car1 Set speed","float",4,670],
    # [1205,"Cassette_change_car car2 Set speed","float",4,674],
    # [1206,"Cassette_transport Set speed","float",4,120],
    # [1202,"Speed set leveller adjustment inlet left ","float",4,196],
    # [1202,"Speed set leveller adjustment inlet right","float",4,200],
    # [1202,"Speed set leveller adjustment outlet left","float",4,204],
    # [1202,"Speed set leveller adjustment outlet right","float",4,208],
    # [1202,"Centering_device1 set val pos","float",4,4],
    # [1202,"Centering_device2 set val pos","float",4,44],
    # [1202,"Centering_device3 set val pos","float",4,84],
    # [1202,"Centering_device4 set val pos","float",4,124],

    # [1205,"Cassette_change_car Actual speed Transport1", "float", 4, 110],
    # [1205,"Cassette_change_car Actual speed Transport2", "float", 4, 306],
    # [1206,"Cassette_transport Act Spd", "float", 4, 10],
    # [1205,"Change_car1 Act Spd", "float", 4, 10],
    # [1205,"Change_car2 Act Spd", "float", 4, 206],
    # #轧辊弯辊位置
    # [1201,"Roller_flexion[1] Act val pos","float",4,8],
    # [1201,"Roller_flexion[2] Act val pos","float",4,48],
    # [1201,"Roller_flexion[3] Act val pos","float",4,88],
    # [1201,"Roller_flexion[4] Act val pos","float",4,128],
    # [1201,"Roller_flexion[5] Act val pos","float",4,168],
    # [1201,"Roller_flexion[6] Act val pos","float",4,208],
    # [1201,"Roller_flexion[7] Act val pos","float",4,248],
    
    # [145,"Right Actual value inlet at screw", "float",4, 44],
    # [145,"Right Actual value inlet for display on MP","float",4,48],
    # [145,"Right Set value inlet at screw","float",4,52],
    # [145,"Right Set value inlet on MP display","float",4,56],
    # [145,"Right Actual value outlet at screw","float",4,64],
    # [145,"Right Actual value outlet for display on MP","float",4,68],
    # [145,"Right Set value outlet at screw","float",4,72],
    # [145,"Right Set value outlet on MP display","float",4,76],
    
    # [146,"Left Actual value inlet at screw", "float",4, 44],
    # [146,"Left Actual value inlet for display on MP","float",4,48],
    # [146,"Left Set value inlet at screw","float",4,52],
    # [146,"Left Set value inlet on MP display","float",4,56],
    # [146,"Left Actual value outlet at screw","float",4,64],
    # [146,"Left Actual value outlet for display on MP","float",4,68],
    # [146,"Left Set value outlet at screw","float",4,72],
    # [146,"Left Set value outlet on MP display","float",4,76],
    # [1202,"inlet_right_side act spd","float",4,10],
    # [1202,"inlet_left_side act spd","float",4,56],
    # [1202,"outlet_right_side act spd","float",4,102],
    # [1202,"outlet_left_side act spd","float",4,148],
    # [1104,"main motor1 v_act","float",4,272],
    # [1104,"main motor2 v_act","float",4,342],
    # [1104,"main motor3 v_act","float",4,372],
    # [1104,"main motor4 v_act","float",4,402],
    # [1208,"Centering Device_1 Act val spd", "float",4, 8],
    # [1208,"Centering Device_2 Act val spd", "float",4, 48],
    # [1208,"Centering Device_3 Act val spd", "float",4, 88],
    # [1208,"Centering Device_4 Act val spd", "float",4, 128],
    # [1103,"Pinchroll_Motor1 V_act","float",4,272],
    # [1103,"Pinchroll_Motor2 V_act","float",4,310],
    # [1103,"Pinchroll_Motor3 V_act","float",4,340],
    # [1103,"Pinchroll_Motor4 V_act","float",4,370],

    # [1103,"Pinchroll_Motor1 I_act","float",4, 280],
    # [1103,"Pinchroll_Motor2 I_act","float",4, 318],
    # [1103,"Pinchroll_Motor3 I_act","float",4, 348],
    # [1103,"Pinchroll_Motor4 I_act","float",4, 378],
    # [1104,"Leveller_Main_Motor1 I_Act","float",4,280],
    # [1104,"Leveller_Main_Motor2 I_Act","float",4,350],
    # [1104,"Leveller_Main_Motor3 I_Act","float",4,380],
    # [1104,"Leveller_Main_Motor4 I_Act","float",4,410],
    # [1104,"Leveller_Main_Motor1 T_Act","float",4,284],
    # [1104,"Leveller_Main_Motor2 T_Act","float",4,354],
    # [1104,"Leveller_Main_Motor3 T_Act","float",4,384],
    # [1104,"Leveller_Main_Motor4 T_Act","float",4,414],
    # [1103,"Pinchroll_Motor1 T_Act","float",4,284],
    # [1103,"Pinchroll_Motor2 T_Act","float",4,322],
    # [1103,"Pinchroll_Motor3 T_Act","float",4,352],
    # [1103,"Pinchroll_Motor4 T_Act","float",4,382],
    # [1205,"Cassette_change_car Transport1 Actual current normed","float",4,118],
    # [1205,"Cassette_change_car Transport2 Actual current normed","float",4,314],
    # [1206,"Cassette_handling Transport Actual current normed","float",4,18],
    # [1205,"Cassette_change_car Transport1 Actual torque normed","float",4,126],
    # [1205,"Cassette_change_car Transport2 Actual torque normed","float",4,322],
    # [1206,"Cassette_handling Transport Actual torque normed","float",4,26],
    # [1304,"Leveller_Plate_Data HEAD_POSITION","float",4,202],
    # [1104,"Leveller_Main_Motor1 V_set","float",4,276],
    # [1104,"Leveller_Main_Motor2 V_set","float",4,346],
    # [1104,"Leveller_Main_Motor3 V_set","float",4,376],
    # [1104,"Leveller_Main_Motor4 V_set","float",4,406],
    # [1205,"Cassette_change_car1 act val pos","float",4,38],
    # [1205,"Cassette_change_car1 act val pos","float",4,234],
    # [1201,"Act_eolng_adj_in_left", "float",4,564],
    # [1201,"Act_eolng_adj_in_right", "float",4,568],
    # [1201,"Act_eolng_adj_out_left", "float",4,572],
    # [1201,"Act_eolng_adj_out_right", "float",4,576],
    # [1103,"Pinchroll_Motor1 V_set","float",4,276],
    # [1103,"Pinchroll_Motor2 V_set","float",4,314],
    # [1103,"Pinchroll_Motor3 V_set","float",4,344],
    # [1103,"Pinchroll_Motor4 V_set","float",4,374],
    # [1201,"Leveller_adjustment Actual counter movement leveller for greasing","word",2,532],
    # [1201,"Leveller_adjustment set counter movement leveller for greasing","word",2,534],
    # [1201,"Leveller_adjustment Actual counter movement roller flexion for greasing","word",2,536],
    # [1201,"Leveller_adjustment Set counter movement roller flexion for greasing","word",2,538],

    # [1208,"Centering_device1 Torque limit positive","word",2,356],
    # [1208,"Centering_device1 Torque limit negative","word",2,358],
    # [1208,"Centering_device2 Torque limit positive","word",2,374],
    # [1208,"Centering_device2 Torque limit negative","word",2,376],
    # [1208,"Centering_device3 Torque limit positive","word",2,392],
    # [1208,"Centering_device3 Torque limit negative","word",2,394],
    # [1208,"Centering_device4 Torque limit positive","word",2,410],
    # [1208,"Centering_device4 Torque limit negative","word",2,412],

    # [1106,"ROLLER_GROUP4 PLATE HEAD_POSITION","float",4,202],
    # [1106,"ROLLER_GROUP4 PLATE TAIL_POSITION","float",4,206],
    # [1105,"ROLLER_GROUP3 PLATE HEAD_POSITION","float",4,202],
    # [1105,"ROLLER_GROUP3 PLATE TAIL_POSITION","float",4,206],

    # [1001,"roller group1 start postion","float",4,40],
    # [1001,"roller group1 end postion","float",4,44],
    # [1001,"roller group2 start postion","float",4,48],
    # [1001,"roller group2 end postion","float",4,52],
    # [1001,"PinchRoll start postion","float",4,56],
    # [1001,"PinchRoll end postion","float",4,60],
    # [1001,"Leveller start postion","float",4,64],
    # [1001,"Leveller end postion","float",4,68],
    # [1001,"roller group3 start postion","float",4,72],
    # [1001,"roller group3 end postion","float",4,76],
    # [1001,"roller group4 start postion","float",4,80],
    # [1001,"roller group4 end postion","float",4,84],
    
    # # [1001,"roller group1 head postion","float",4,202],
    # # [1001,"roller group1 tail postion","float",4,206],

    # [1101,"ROLLER_GROUP1 PLATE HEAD_POSITION", "float", 4,202],
    # [1101,"ROLLER_GROUP1 PLATE TAIL_POSITION","float",4,206],
    # [1102,"ROLLER_GROUP2 PLATE HEAD_POSITION","float",4,202],
    # [1102,"ROLLER_GROUP2 PLATE TAIL_POSITION","float",4,206],
    # [1103,"PinchRoll_1/2 PLATE HEAD_POSITION","float",4,202],
    # [1103,"PinchRoll_1/2 PLATE TAIL_POSITION","float",4,206],
    # [1104,"Leveller_Main_Motor PLATE HEAD_POSITION","float",4,202],
    # [1104,"Leveller_Main_Motor PLATE TAIL_POSITION","float",4,206],
    # [1105,"ROLLER_GROUP3 PLATE HEAD_POSITION","float",4,202],
    # [1105,"ROLLER_GROUP3 PLATE TAIL_POSITION","float",4,206],
    # [1106,"ROLLER_GROUP4 PLATE HEAD_POSITION","float",4,202],
    # [1106,"ROLLER_GROUP4 PLATE TAIL_POSITION","float",4,206],

    # [1208,"Centering_device Motor1 Act_rot_spd","float",4,166],
    # [1208,"Centering_device Motor2 Act_rot_spd","float",4,212],
    # [1208,"Centering_device Motor3 Act_rot_spd","float",4,258],
    # [1208,"Centering_device Motor4 Act_rot_spd","float",4,304],
    # [1208,"Centering_device1 MDI set val pos","int",4,348],
    # [1208,"Centering_device2 MDI set val pos","int",4,366],
    # [1208,"Centering_device3 MDI set val pos","int",4,384],
    # [1208,"Centering_device4 MDI set val pos","int",4,402],
    # [1101,"Roller Group1 v_act","float",4,272],
    # [1102,"Roller Group2 v_act","float",4,272],
    # [1105,"Roller Group3 v_act","float",4,272],
    # [1106,"Roller Group4 v_act","float",4,272],
    # [508,"LINE_ENTRY_SPEED","float",4,4],
    # [508,"LINE_EXIT_SPEED","float",4,8],
    # [1103,"PinchRoll valse stand pressure actual  value[bar]","float",4,398],
    # [1101,"ROLLER_GROUP1 Roller Occupied","bool",1,250,3],
    # [1102,"ROLLER_GROUP2 Roller Occupied","bool",1,250,3],
    # [1103,"PinchRoll_1/2 Occupied","bool",1,250,3],
    # [1104,"Leveller_Main_Motor roller occupied","bool",1,250,3],
    # [1105,"ROLLER_GROUP3 Roller Occupied","bool",1,250,3],
    # [1106,"ROLLER_GROUP4 Roller Occupied","bool",1,250,3],
    # [1101,"ROLLER_GROUP1 plate forward run in","bool",1,251,0],
    # [1102,"ROLLER_GROUP2 plate forward run in","bool",1,251,0],

    # [1101,"ROLLER_GROUP1 request the plate out and go to next roller","bool",1,250,4],
    # [1101,"ROLLER_GROUP1 forword auto/manu mode:slave", "bool",1,250,5],
    # [1101,"ROLLER_GROUP1 forword auto/manu mode:master", "bool",1,250,6],
    # [1101,"ROLLER_GROUP1 forword auto mode:preparing", "bool",1,250,7],

    [1001,"Before In Table1","bool",1,100,1],    
    [1001,"After Out Table1","bool",1,114,1],
    #[1001,"Before Out Table1","bool",1,112,1],
    [1001,"Before In Table2","bool",1,104,1],
    [1001,"After Out Table2","bool",1,116,1],
    [1001,"Before PinchRoll","bool",1,108,1],
    [1001,"Before Leveller","bool",1,110,1],

    [1103,"PinchRoll Occupied","bool",1,250,3],
    [1104,"Leveller Occupied","bool",1,250,3],
    [1104,"Forward mode","bool",1,250,0],
    [1104,"Reverse mode","bool",1,250,1],
    [1104,"Forward running","bool",1,251,6],
    [1104,"Reverse running","bool",1,251,7],    

    # [1102,"ROLLER_GROUP2 request the plate out and go to next roller","bool",1,250,4],
    # [1102,"ROLLER_GROUP2 forword auto/manu mode:slave", "bool",1,250,5],
    # [1102,"ROLLER_GROUP2 forword auto/manu mode:master", "bool",1,250,6],
    # [1102,"ROLLER_GROUP2 forword auto mode:preparing", "bool",1,250,7],

    # [1104,"Leveller_Main_Motor1 T_act","float",4,284],
    # [1104,"Leveller_Main_Motor2 T_act","float",4,354],
    # [1104,"Leveller_Main_Motor3 T_act","float",4,384],
    # [1104,"Leveller_Main_Motor4 T_act","float",4,414],

    
    #L2_SET_DATA
    # [1304,"L2_SET_DATA SET_LEVELLER_INLET [mm]","float",4,104],
    # [1304,"L2_SET_DATA SET_LEVELLER_OUTLET [mm]","float",4,108],
    # [1304,"L2_SET_DATA SET_TILD_LEFT [mm]","float",4,112],
    # [1304,"L2_SET_DATA SET_TILD_RIGHT[mm] ","float",4,116],
    # [1304,"L2_SET_DATA SET_MIDDLE_HEIGHT [mm]","float",4,120],
    # [1304,"L2_SET_DATA SET_CURVE_PROFILE [%]","float",4,124],
    # [1304,"L2_SET_DATA SET_ELONGATION [mm]","float",4,132],
    [1304,"L1_SET_DATA SET_LEVELLER_INLET[mm]","float",4,148],
    [1304,"L1_SET_DATA SET_LEVELLER_OUTLET [mm]","float",4,152],
    [1304,"L1_SET_DATA SET_TILD_LEFT [mm]","float",4,156],
    [1304,"L1_SET_DATA SET_TILD_RIGHT [mm]","float",4,160],
    [1304,"L1_SET_DATA SET_MIDDLE_HEIGHT [mm]" ,"float",4,164],
    [1304,"L1_SET_DATA SET_CURVE_PROFILE [%]","float",4,168],

    [849,"Leverler inlet manual","float",4 ,416],  # 入口设定
    [849,"Leverler outlet manual","float",4,420],  # 出口设定
    [849,"Leverler flexion manual","float",4,424], # 弯辊量
    [849,"Leverler set curve profile","float",4,428], # 

    [803,"Table1 Speed","float",4,4],
    [803,"Table2 Speed","float",4,38],

    # [1098,"Add Plate ID","string",20,0],
    # [849,"Plate Length","float",4,48],
]

SHAPE_DATA_ITEM = [
    "Yield Strength",
    "Tensile Strength",
    "Cross 1m Gap Limit",
    "Length 1m Gap Limit",
    "Length 2m Gap Limit",
    "Full Length Gap Limit",
    "Full Cross Gap Limit",
    "xSize",
    "ySize",
    "PlateId",
    "Left Mean Amplitude",
    "Center Mean Amplitude",
    "Right Mean Amplitude",
    "Ski Head",
    "Ski Tail",
    "Left Fiber Height",
    "LQ Fiber Height",
    "Center Fiber Height",
    "RQ Fiber Height",
    "Right Fiber Height",
    "Left Fiber Pos",
    "LQ Fiber Pos",
    "Center Fiber Pos",
    "RQ Fiber Pos",
    "Right Fiber Pos",
    "Left Fiber Wave Length",
    "LQ Fiber Wave Length",
    "Center Fiber Wave Length",
    "RQ Fiber Wave Length",
    "Right Fiber Wave Length",
    "Left Fiber Wave Count",
    "LQ Fiber Wave Count",
    "Center Fiber Wave Count",
    "RQ Fiber Wave Count",
    "Right Fiber Wave Count",
    "Full Length Max Gap",
    "Full Length Gap X Pos",
    "Full Length Gap Y Pos",
    "Full Cross Max Gap",
    "Full Cross Gap X Pos",
    "Full Cross Gap Y Pos",
    "Cross 1m Max Gap",
    "Cross 1m Gap X Pos",
    "Cross 1m Gap Y Pos",
    "Length 1m Max Gap",
    "Length 1m Gap X Pos",
    "Length 1m Gap Y Pos",
    "Length 2m Max Gap",
    "Length 2m Gap X Pos",
    "Length 2m Gap Y Pos",
    "Min Width",
    "Mean Width",
    "Max Width",
    "Max Centerline Offset",
    "Length",
    "Plate Angle",
    "Plate Offset",
    "ASTM Gap@Max",
    "ASTM X@Max",
    "ASTM Y@Max",
    "ASTM Wavecount@Max",
    "EN N Gap@Max",
    "EN N X@Max",
    "EN N Y@Max",
    "EN N RPD@Max",
    "EN S Gap@Max",
    "EN S X@Max",
    "EN S Y@Max",
    "EN S RPD@Max",
    "RequirementCode",
    "Thickness",
]

EXP_FIELD_NAMES = [
   "_id",
    "plate_id",
    "material_id",
    "steel grade",
    "plate length",
    "plate width",
    "plate thickness",
    "yield point",
    "tensile strength",
    "RULER_1M_CROSS",
    "RULER_1M_LENGTH",
    "RULER_2M_LENGTH",
    "plate act temperature",
    "Roller_flexion[1] Act val pos",
    "Roller_flexion[2] Act val pos",
    "Roller_flexion[3] Act val pos",
    "Roller_flexion[4] Act val pos",
    "Roller_flexion[5] Act val pos",
    "Roller_flexion[6] Act val pos",
    "Roller_flexion[7] Act val pos",
    #L1 setup
    "L1_SET_DATA SET_LEVELLER_INLET[mm]",
    "L1_SET_DATA SET_LEVELLER_OUTLET [mm]",
    "L1_SET_DATA SET_TILD_LEFT [mm]",
    "L1_SET_DATA SET_TILD_RIGHT [mm]",
    "L1_SET_DATA SET_MIDDLE_HEIGHT [mm]",
    "L1_SET_DATA SET_CURVE_PROFILE [%]",
    #user set
    "Leverler inlet manual",
    "Leverler outlet manual",
    "Leverler flexion manual",
    #1st calculation
    "1st Leverler inlet manual",
    "1st Leverler outlet manual",
    "1st Leverler flexion manual",
    "1st flmg_mean",
    "1st fcmg_mean",
    "1st flmg_prct_90",
    "1st fcmg_prct_90",
    #2nd calculation
    "2nd Leverler inlet manual",
    "2nd Leverler outlet manual",
    "2nd Leverler flexion manual",
    "2nd flmg_mean",
    "2nd fcmg_mean",
    "2nd flmg_prct_90",
    "2nd fcmg_prct_90",
    "pre flmg_mean",
    "pre fcmg_mean",
    "pre flmg_prct_90",
    "pre fcmg_prct_90",
    "Yield Strength",
    "Tensile Strength",
    "Cross 1m Gap Limit",
    "Length 1m Gap Limit",
    "Length 2m Gap Limit",
    "Full Length Gap Limit",
    "Full Cross Gap Limit",
    # "xSize",
    # "ySize",
    # "Left Mean Amplitude",
    # "Center Mean Amplitude",
    # "Right Mean Amplitude",
    # "Ski Head",
    # "Ski Tail",
    # "Left Fiber Height",
    # "LQ Fiber Height",
    # "Center Fiber Height",
    # "RQ Fiber Height",
    # "Right Fiber Height",
    # "Left Fiber Pos",
    # "LQ Fiber Pos",
    # "Center Fiber Pos",
    # "RQ Fiber Pos",
    # "Right Fiber Pos",
    # "Left Fiber Wave Length",
    # "LQ Fiber Wave Length",
    # "Center Fiber Wave Length",
    # "RQ Fiber Wave Length",
    # "Right Fiber Wave Length",
    # "Left Fiber Wave Count",
    # "LQ Fiber Wave Count",
    # "Center Fiber Wave Count",
    # "RQ Fiber Wave Count",
    # "Right Fiber Wave Count",
    "Full Length Max Gap",
    "Full Length Gap X Pos",
    "Full Length Gap Y Pos",
    "Full Cross Max Gap",
    "Full Cross Gap X Pos",
    "Full Cross Gap Y Pos",
    "Cross 1m Max Gap",
    "Cross 1m Gap X Pos",
    "Cross 1m Gap Y Pos",
    "Length 1m Max Gap",
    "Length 1m Gap X Pos",
    "Length 1m Gap Y Pos",
    "Length 2m Max Gap",
    "Length 2m Gap X Pos",
    "Length 2m Gap Y Pos",
    # "Min Width",
    # "Mean Width",
    # "Max Width",
    # "Max Centerline Offset",
    # "Length",
    # "Plate Angle",
    # "Plate Offset",
    # "ASTM Gap@Max",
    # "ASTM X@Max",
    # "ASTM Y@Max",
    # "ASTM Wavecount@Max",
    # "EN N Gap@Max",
    # "EN N X@Max",
    # "EN N Y@Max",
    # "EN N RPD@Max",
    # "EN S Gap@Max",
    # "EN S X@Max",
    # "EN S Y@Max",
    # "EN S RPD@Max",
    # "RequirementCode",
    # "Thickness", 
]

#list for shape data
#item {"_id":ObjectId,"plate_id":"WW"}
QUE_FIN_PLATE = Queue(16)

LIST_RECV_REC=[]
